package everyday;

import java.util.Arrays;

public class T2389 {
    public int[] answerQueries(int[] nums, int[] queries) {
        int[] sums = new int[nums.length + 1];
        int[] answer=new int[queries.length];
        sums[0]=0;
        Arrays.sort(nums);
        Arrays.fill(answer,nums.length);
        for (int i = 0; i <nums.length ; i++) {
            sums[i+1]=sums[i]+nums[i];
        }
        for (int i = 0; i <queries.length ; i++) {
            for (int j = 1; j <sums.length ; j++) {
                if (queries[i]<sums[j]){
                    answer[i]=j-1;
                    break;
                }
            }
        }
        return answer;
    }

}
